package mango.web.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Vo implements IsSerializable {
	public List<String> getStringList(String property) {
		List<String> result = new ArrayList<String>();
		String[] arr = property.split("&&");
		for (int i = 0; i < arr.length; i++) {
			//if (arr[i] == null || "".equals(arr[i])) continue;
			arr[i] = arr[i].replaceAll("&", "");
			result.add(arr[i]);
		}
		return result;
	}

	public String setStringList(String property, List<String> list) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			sb.append("&").append(list.get(i)).append("&");
		}
		property = sb.toString();
		return property.toString();
	}

	public String addStringList(String property, Object obj) {
		if (this.inStringList(property, obj) == false) property = new StringBuffer().append(property).append("&").append(obj).append("&").toString();
		return property;
	}

	public String removeStringList(String property, Object obj) {
		property = property.replaceAll("&" + obj + "&", "");
		return property;
	}

	public Boolean inStringList(String property, Object obj) {
		if (property.indexOf("&" + obj + "&") >= 0) return true;
		return false;
	}

	public String toStringList(String property, String sign) {
		if (!"".equals(property)) {
			property = "&" + property.replaceAll(sign, "&&") + "&";
		}
		return property;
	}

	public String toStringRead(String property, String sign) {
		if (!"".equals(property)) {
			property = property.substring(1, property.length() - 1).replaceAll("&&", sign);
		}
		return property;
	}

	public String sqlRange(String property) {
		String str = property.trim();
		if (str.startsWith("<") || str.startsWith(">") || str.startsWith("=")) return str;
		else if (str.indexOf("..") >= 0) return "BETWEEN " + str.replace("..", " AND ");
		else return "=" + str;
	}

	public String tdNull0(String str) {
		if (str == null || "0".equals(str)) return "&nbsp";
		return str;
	}

	public String tdNull0(Integer str) {
		if (str == null || str == 0) return "&nbsp";
		return str + "";
	}
}
